import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    name: 'Layout',
    component: () => import('@/layout/index.vue'),
    redirect: '/dashboard',
    children: [
      {
        path: '/dashboard',
        name: 'Dashboard',
        component: () => import('@/views/Dashboard.vue'),
        meta: { title: '仪表盘', icon: 'DataBoard' }
      },
      {
        path: '/employees',
        name: 'Employees',
        component: () => import('@/views/employee/index.vue'),
        meta: { title: '员工管理', icon: 'User' }
      },
      {
        path: '/employees/add',
        name: 'EmployeeAdd',
        component: () => import('@/views/employee/add.vue'),
        meta: { title: '添加员工', icon: 'Plus', hidden: true }
      },
      {
        path: '/employees/edit/:id',
        name: 'EmployeeEdit',
        component: () => import('@/views/employee/edit.vue'),
        meta: { title: '编辑员工', icon: 'Edit', hidden: true }
      },
      {
        path: '/salary',
        name: 'Salary',
        component: () => import('@/views/salary/index.vue'),
        meta: { title: '工资管理', icon: 'Money' }
      },
      {
        path: '/salary/calculation',
        name: 'SalaryCalculation',
        component: () => import('@/views/salary/calculation.vue'),
        meta: { title: '工资计算', icon: 'Calculator', hidden: true }
      },
      {
        path: '/salary/comparison',
        name: 'SalaryComparison',
        component: () => import('@/views/salary/comparison.vue'),
        meta: { title: '工资对比', icon: 'TrendCharts', hidden: true }
      },
      {
        path: '/schedule',
        name: 'Schedule',
        component: () => import('@/views/schedule/index.vue'),
        meta: { title: '排班管理', icon: 'Calendar' }
      },
      {
        path: '/schedule/employee/:id',
        name: 'EmployeeSchedule',
        component: () => import('@/views/schedule/employee.vue'),
        meta: { title: '员工排班表', icon: 'User', hidden: true }
      },
      {
        path: '/schedule/admin',
        name: 'AdminSchedule',
        component: () => import('@/views/schedule/admin.vue'),
        meta: { title: '管理员排班表', icon: 'Setting', hidden: true }
      },
      {
        path: '/customers',
        name: 'Customers',
        component: () => import('@/views/customer/index.vue'),
        meta: { title: '客户管理', icon: 'UserFilled' }
      },
      {
        path: '/rooms',
        name: 'Rooms',
        component: () => import('@/views/room/index.vue'),
        meta: { title: '房间管理', icon: 'House' }
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/Login.vue'),
    meta: { title: '登录', hidden: true }
  },
  {
    path: '/:pathMatch(.*)*',
    name: 'NotFound',
    component: () => import('@/views/404.vue'),
    meta: { title: '页面不存在', hidden: true }
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  // 设置页面标题
  if (to.meta.title) {
    document.title = `${to.meta.title} - 自动排班系统`
  }
  next()
})

export default router